<template>
  <div>
    <h1>App</h1>
    <div>
      <button @click="Comp = 'News'">新闻</button>
      <button @click="Comp = 'Music'">音乐</button>
      <button @click="Comp = 'Play'">游戏</button>
    </div>

    <!-- 
      
      keep-alive内置组件:包裹动态组件时，会缓存不活动的组件实例，而不是销毁它们
      keep-alive可以通过属性来控制具体缓存哪个组件

      include属性:可以是一个字符串或者数组,规定哪个组件可以被缓存
      exclude属性:可以是一个字符串或者数据,规定哪一个组件不能被缓存
      max:规定最多缓存几个
     -->
    <!-- <keep-alive include="Music">
      <component :is="Comp"></component>
    </keep-alive> -->
    <keep-alive :include="['Music', 'News', 'Play']" :max="2">
      <component :is="Comp"></component>
    </keep-alive>
    <!-- <keep-alive exclude="Music">
      <component :is="Comp"></component>
    </keep-alive> -->
    <!--  <keep-alive :exclude="['Music']">
      <component :is="Comp"></component>
    </keep-alive> -->
  </div>
</template>

<script>
import Music from "@/components/Music";
import Play from "@/components/Play";
import News from "@/components/News";
export default {
  name: "App",
  components: {
    Play,
    News,
    Music,
  },
  data() {
    return {
      Comp: "News",
    };
  },
};
</script>

<style></style>
